﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace UrlParser
{
    class Program
    {
        static void Main()
        {
            string text = "Write a program that parses URL in format [protocol]://[server]/[resource] and extracts its elements. For example: http://www.devbg.org/forum/index.php";
            string pattern = @"\b(?<protocol>[a-z]+)://(?<server>[^/]+)/(?<resource>\S+[A-Za-z])\b";

            Match match = Regex.Match(text, pattern);
            while (match.Success)
            {
                GroupCollection groups = match.Groups;

                Console.WriteLine("[protocol] = \"{0}\", [server] = \"{1}\", [resource] = \"{2}\"",
                    groups["protocol"], groups["server"], groups["resource"]);

                match = match.NextMatch();
            }
        }
    }
}
